package day07_14.day07;

import java.util.Stack;

public class Main02 {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        Stack<Character> stack = new Stack<>();
        char[] cArray = A.toCharArray();
        for (int i = 0; i < cArray.length; i++) {
            if (stack.isEmpty() ){
                if (cArray[i] != '('){
                    return false;
                }
            }
            if (cArray[i] != '(' && cArray[i] != ')'){
                return false;
            }else {
                if (cArray[i] != ')') {
                    stack.push(cArray[i]);
                } else {
                    stack.pop();
                }
            }
        }
        if (!stack.isEmpty()){
            return false;
        }else {
            return true;
        }
    }
}
